import pandas as pd

# 读取CSV文件
input_file = 'wuhan_price_data_with_coords_?.csv'
df = pd.read_csv(input_file)

# 删除经纬度任一为空的行
df_cleaned = df.dropna(subset=['longitude', 'latitude'])

# 删除指定的列
columns_to_drop = ['城市', '所属省份', '行政区划代码', 'Unnamed: 0', 'Unnamed: 18', '所属地域']
df_cleaned = df_cleaned.drop(columns=columns_to_drop, errors='ignore')

# 保存清理后的数据到新CSV文件
output_file = 'wuhan_price_data_with_coords_?_cleaned.csv'
df_cleaned.to_csv(output_file, index=False, encoding='utf-8')

print(f"原始数据行数: {len(df)}")
print(f"清理后数据行数: {len(df_cleaned)}")
print(f"已删除 {len(df) - len(df_cleaned)} 条缺失经纬度的数据")
print(f"已删除的列: {columns_to_drop}")
print(f"清理后的数据已保存到 {output_file}")